function a(a) {
    if (a && a.length > 0) {
        t(a);
        var e = n.data.wxSearchData;
        e.value = a, n.setData({
            wxSearchData: e
        }), r(a);
    }
}

function e() {
    var a = [];
    try {
        if (a = wx.getStorageSync("wxSearchHisKeys")) {
            var e = n.data.wxSearchData;
            e.his = a, n.setData({
                wxSearchData: e
            });
        }
    } catch (a) {}
}

function t(a) {
    if (a && 0 != a.length) {
        var t = wx.getStorageSync("wxSearchHisKeys");
        t ? (t.indexOf(a) < 0 && t.unshift(a), wx.setStorage({
            key: "wxSearchHisKeys",
            data: t,
            success: function() {
                e(n);
            }
        })) : ((t = []).push(a), wx.setStorage({
            key: "wxSearchHisKeys",
            data: t,
            success: function() {
                e(n);
            }
        }));
    }
}

var c = [], r = null, s = null, n = null;

module.exports = {
    init: function(a, t, i, h, u) {
        n = a, c = i, r = h, s = u;
        var w = {}, x = {
            barHeight: 43
        };
        w.hotKeys = t, wx.getSystemInfo({
            success: function(a) {
                var e = a.windowHeight;
                x.seachHeight = e - 43, w.view = x, n.setData({
                    wxSearchData: w
                });
            }
        }), e(n);
    },
    wxSearchInput: function(a) {
        var e = a.detail.value, t = n.data.wxSearchData, r = [];
        if (e && e.length > 0) for (var s = 0; s < c.length; s++) {
            var i = c[s];
            -1 != i.indexOf(e) && r.push(i);
        }
        t.value = e, t.tipKeys = r, n.setData({
            wxSearchData: t
        });
    },
    wxSearchKeyTap: function(e) {
        a(e.target.dataset.key);
    },
    wxSearchDeleteAll: function() {
        wx.removeStorage({
            key: "wxSearchHisKeys",
            success: function(a) {
                var e = [], t = n.data.wxSearchData;
                t.his = e, n.setData({
                    wxSearchData: t
                });
            }
        });
    },
    wxSearchConfirm: function(e) {
        "back" == e.target.dataset.key ? s() : a(n.data.wxSearchData.value);
    },
    wxSearchClear: function() {
        var a = n.data.wxSearchData;
        a.value = "", a.tipKeys = [], n.setData({
            wxSearchData: a
        });
    }
};